package com.jk.service.impl;

import com.jk.dao.BookDao;
import com.jk.pojo.BookEntity;
import com.jk.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;


    @Override
    public HashMap<String, Object> find(BookEntity book) {

        int start = (book.getPage()-1)*book.getRows();

        int count = bookDao.findCount(book);

        List<BookEntity> list = bookDao.find(start,book);

        HashMap<String, Object> map = new HashMap<>();
        map.put("total",count);
        map.put("rows",list);

        return map;
    }

    @Override
    public void addorup(BookEntity book) {
        if (book.getBookId() == null){
            bookDao.add(book);
        }else{
            bookDao.update(book);
        }
    }

    @Override
    public void del(Integer id) {
            bookDao.del(id);
    }

    @Override
    public BookEntity findById(Integer id) {
        return bookDao.findById(id);
    }
}
